window.addEventListener("DOMContentLoaded", function() {
	// 点击回到顶部
	let toTop = document.getElementById("toTop");
	toTop.addEventListener("click", function() {
		clearInterval(this.set);
		let _this = this;
		let scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
		if(scrolltop > 0) {
			this.set = null;
			let tenth = scrolltop / 20;
			this.set = setInterval(function() {

				//document.documentElement.scrollTop -= tenth;
				window.scrollTo(0, (scrolltop - tenth));
				scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
				if(scrolltop <= 0) {
					clearInterval(_this.set);
					_this.set = null;
					return;
				}
				scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
				tenth = scrolltop / 20;
			}, 20);
			document.addEventListener("wheel" || "mousewheel", function(e) {
				clearInterval(_this.set);
				_this.set = null;
				return;
			}); // 按空格键时会出现一点bug，就是相对于多次点击回到顶部按钮，不太好
		}

	});
	window.addEventListener("scroll", function() {
		let scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
		if(scrolltop > 300) {
			toTop.classList.add("showToTop");
			toTop.children[0].disabled = "";
			return;
		}
		toTop.children[0].disabled = "disabled";
		toTop.classList.remove("showToTop");
	});
	
	jQuery.noConflict();
	jQuery(function($) {
		$(".character-description > li").mouseover(function() {
			let index = $(this).index();
			let top = $(".show-advantage-ul > li").eq(index).position().top;
			$(".show-advantage-ul").css({
				"top": -top + "px"
			});
			$(this).css({
				backgroundColor: "orange"
			}).siblings().css({
				backgroundColor: ""
			});
		});
		// 每次窗口缩放时，都要让这个盒子的left变为0，否则后面左移或右移后页面一片空白，因为之前的宽度与窗口调整后的宽度不一样
		$(window).resize(function() {
			$(".show-advantage-ul").css({
				"top": 0
			});
			$(".character-description > li").eq(0).css({
				backgroundColor: "orange"
			}).siblings().css({
				backgroundColor: ""
			});
		});
		$("#city-head-letter-ul").children().click(function() {
			let index = $(this).index();
			
			$("#cityLists .detaCityList").children("ul.display-flex").eq(index).stop(true).slideDown(300)
			.siblings().stop(true).slideUp(300);
			
		});
		$("#select-cities > p").click(function() {
			$("#cityLists").stop(true).toggleClass("show-height");
		});
		$("#cityLists .detaCityList > ul.display-flex > li").click(function() {
			$("#city-addr").html($(this).children("a").html());
		});
	});
});